package com.example.datn.activities;

import java.util.List;

import com.example.datn.R;
import com.example.datn.adapter.PaPerAdapter;
import com.example.datn.objects.RssObject;
import com.example.datn.utils.RssParser;
import com.example.datn.utils.Variables;

import android.app.Activity;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class TintucRRSActivity extends ListActivity {
	private ProgressDialog diaglog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		PaPerAdapter adapter = new PaPerAdapter(TintucRRSActivity.this,
				R.id.tvPaper, Variables.PAPER_CATEGORIES);
		setListAdapter(adapter);

	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);

		

		
		diaglog=ProgressDialog.show(TintucRRSActivity.this,"","Loading..");
	new Catelogy().execute(position);	
	}
	class Catelogy extends AsyncTask<Integer, Void, Void> {
int position;
		@Override
		protected Void doInBackground(Integer... params) {
			position=params[0];
			int key =position;
			RssParser parser = new RssParser();
			List<RssObject> item = parser
					.getNewList(Variables.PAPER_LINKS[position]);
			System.out.printf("Rsss   "+item.size());
			Variables.newsMap.put(key, item);
			return null;
		}
		@Override
		protected void onPostExecute(Void result) {
if(diaglog!=null){
	diaglog.dismiss();
}
Intent intent = new Intent(TintucRRSActivity.this,
		ListTintucActivity.class);

intent.putExtra("paper", position);
startActivity(intent);
			super.onPostExecute(result);
		}
		
	}

	
}


